<?php

class App_Validate_UniqueUsername extends Zend_Validate_Abstract
{
    const USER_EXISTS = 'userExists';

    /**
     * @var array
     */
    protected $_messageTemplates = array(
        self::USER_EXISTS => " is already in use."
    );

    public function isValid($value)
    {
        $this->_setValue((string) $value);

        $user = Doctrine_Core::getTable("Users")->findOneByUsername($value);
        
        if ($user) {
            $this->_error();
        	return false;
		}

        return true;
    }

}

